import { reactive } from "vue";

import { is_login } from "@/service/auth";
import { user } from "@/server/user";

export const userInfo = reactive({
    account: "",       // 账号
    registerType: 0,   // 账号类型: { 0: 邮箱注册, 1: 手机注册 }
    balance: 0,        // 可用余额
    freeze: 0,         // 冻结金额
    unpaid: 0,         // 未支付
    authStatus: 0      // 认证状态: { 0: 未认证, 1: 待审核, 2: 已认证, 3: 审核拒绝 }
});

export const userService = {
    async getUserInfo() {
        let res = await user.getUserInfo();
        if (res.success) {
            if (res.data.code == 200) {
                console.log(res.data.data);
                is_login.value = true;
                Object.assign(userInfo, res.data.data);
            } else {
                is_login.value = false;
            }
        } else {
            is_login.value = false;
        }
    },
};